package com.chain.BrotherExchange.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chain.BrotherExchange.R;
import com.chain.BrotherExchange.data.model.CoinAssetsDetails;
import com.chain.BrotherExchange.utils.DateUtils;

import java.util.List;

/**
 * 币币资产详情
 */
public class CoinDetailsListAdapter extends RecyclerView.Adapter<CoinDetailsListAdapter.ViewHolder> {

    private List<CoinAssetsDetails.DataBean.ListBean.ItemsBean> mDetailsList;

    @NonNull
    @Override
    public CoinDetailsListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.item_coin_assets_details, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull CoinDetailsListAdapter.ViewHolder holder, int i) {
        CoinAssetsDetails.DataBean.ListBean.ItemsBean bean = mDetailsList.get(i);
        holder.mCoinTypeTextView.setText(bean.getToken_name());
        holder.mNumberTextView.setText(bean.getNum());
        holder.mGasTextView.setText(bean.getFee());
        holder.mTypeTextView.setText(bean.getOptText());
        holder.mDateTextView.setText(DateUtils.timestampToTimeStyle_3(bean.getDeal_time()));
    }

    @Override
    public int getItemCount() {
        return mDetailsList != null ? mDetailsList.size() : 0;
    }

    public void setOrder(List<CoinAssetsDetails.DataBean.ListBean.ItemsBean> result) {
        this.mDetailsList = result;
        notifyDataSetChanged();
    }

    public void addOrder(List<CoinAssetsDetails.DataBean.ListBean.ItemsBean> source) {
        this.mDetailsList.addAll(source);
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView mGasTextView;
        private final TextView mDateTextView;
        private final TextView mTypeTextView;
        private final TextView mNumberTextView;
        private final TextView mCoinTypeTextView;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            mCoinTypeTextView = itemView.findViewById(R.id.coin_type_text);
            mDateTextView = itemView.findViewById(R.id.date_text);
            mNumberTextView = itemView.findViewById(R.id.number_text);
            mTypeTextView = itemView.findViewById(R.id.type_text);
            mGasTextView = itemView.findViewById(R.id.gas_text);
        }
    }
}
